"use strict";

const Service = require("egg").Service;

class ShoppingService extends Service {
    //商品列表数据查询
    async inquire() {
        let sql = "select * from shopping";
        return await this.app.mysql.query(sql);
    }
    //商品添加
    async add(shopname, lettor, price, num) {
        let sql =
            "insert into shopping (shopname,lettor,price,num) values (?,?,?,?)"; //插入的sql
        let params = [shopname, lettor, price, num];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
    //商品删除
    async remove(id) {
        let sql = "delete from shopping where id = ?";
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
    //商品修改
    async alter(num, id) {
        let sql = "update shopping set num=? where id=?";
        let params = [num, id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = ShoppingService;
